import { _decorator, Component, Node, tween, Vec3 } from 'cc';
import { EffectLoad } from './EffectLoad';
const { ccclass, property } = _decorator;

@ccclass('SingleEffect')
/**
 * 动画效果
 */
export class SingleEffect extends Component {

    //效果层
    public EffectLoad: EffectLoad = null;

    /**
     * 播放动画
     */
    public PlayAni() {
        for (let i = 0; i < this.node.children.length; i++) {
            this.node.children[i].setScale(0, 0, 0);
            this.node.children[i].setPosition(new Vec3(0, 0, 0));

            tween(this.node.children[i]).to(0.2, {
                scale: new Vec3(0.3, 0.3, 0.3),
                position: new Vec3(
                    25 * Math.cos(360 / this.node.children.length * i * Math.PI / 180),
                    25 * Math.sin(360 / this.node.children.length * i * Math.PI / 180),
                    0
                )
            }).to(0.2, {
                scale: new Vec3(0, 0, 0),
                position: new Vec3(
                    50 * Math.cos(360 / this.node.children.length * i * Math.PI / 180),
                    50 * Math.sin(360 / this.node.children.length * i * Math.PI / 180),
                    0
                )
            }).delay(0.1).start();
        }

        this.scheduleOnce(() => {
            this.EffectLoad.RemoveEffect(this.node);
        }, 0.6)
    }


}


